package com.kwlt.smc.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.kwlt.smc.dao.UserDao;
import com.kwlt.smc.entity.User;



/**
 * 用户管理类
 * @author xushunxin
 *
 */
//Spring Bean的标识.
@Component
//默认将类中的所有public函数纳入事务管理.
@Transactional(readOnly = true)
public class UserService {
	private static Logger logger = LoggerFactory.getLogger(UserService.class);
	@Autowired
	private UserDao userDao;
	
	/**
	 * 查询用户详细信息
	 * @param id
	 * @return
	 */
	public User getUser(Long id){
		return userDao.findOne(id);
	}
	
	/**
	 * 保存用户信息
	 * @param user
	 */
	@Transactional(readOnly = false)
	public void saveUser(User user){
		userDao.save(user);
	}
	
	/**
	 * 删除用户信息
	 * @param id 用户信息ID
	 */
	@Transactional(readOnly = false)
	public void deleteUser(Long id){
		User user = getUser(id);
		userDao.delete(id);
	}
	
	/**
	 * 查询用户信息列表
	 * @param
	 * @return
	 */
	public Page<User> getUserAll(Pageable pager){
		Page<User> page = userDao.findAll(pager);
		return page;
	}
	
	
	/**
	 * 通过登录名，密码验证验证用户。
	 */
	public User findUserByLoginNamePassword(String loginName,String password){
		return userDao.findByLoginNamePassword(loginName,password);
	}


	public User findUserByUserNumbers(String userNumber) {
		return userDao.findByUserNumbers(userNumber);
	}
}
